

from rest_framework import serializers
from django.contrib.auth.models import Permission,ContentType


class ContentTypeModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = ContentType
        fields = [
            'id',
            'name'
        ]


class PermModelSerializer(serializers.ModelSerializer):
    # 序列化为权限的类型的名称
    # StringRelatedField：无法参与反序列化操作的
    # content_type = serializers.StringRelatedField()

    class Meta:
        model = Permission
        fields = [
            'id',
            'name',
            'codename',
            'content_type'
        ]